package com.zfk.transaction.util;

import com.zfk.transaction.util.enums.RequestType;
import lombok.Data;

/**
 * 响应类
 */
@Data
public class Response<T>{
    private T data;
    private int code;
    private String message;

    public Response(T data, int code, String message) {
        this.data = data;
        this.code = code;
        this.message = message;
    }

    public Response(String message,T data){
        this.message = message;
        this.data = data;
    }

    public Response(RequestType requestType, T data) {
        this.message = requestType.getMessage();
        this.code = requestType.getCode();
        this.data = data;
    }

    public Response (RequestType requestType){
        this.message = requestType.getMessage();
        this.code = requestType.getCode();
    }

    public Response(String message,int code){
        this.message = message;
        this.code = code;
    }

    public Response(String message){
        this.message = message;
    }

    public Response(Exception e){
        this.message = e.getMessage();
    }


    public static <T> Response<T> ok(T data) {
        return new Response(RequestType.SUCCESS, data);
    }

    public static Response systemError() {
        return new Response(RequestType.INTERNAL_SERVER_ERROR);
    }

    public static Response error(Exception e) {
        return new Response(e);
    }

    public static Response error(int code, String message) {
        return new Response(message,code);
    }

    public static Response error(RequestType exceptionType) {
        return new Response(exceptionType);
    }

    public static Response error(String message){
        return new Response(message);
    }

    public static Response ok() {
        return new Response(RequestType.SUCCESS, null);
    }
}
